#include "native/java/lang/Double.hpp"
#include "rtda/heap/class.h"

#include <cstring>

namespace jvm {
    namespace lang {

        const std::string DoubleNative::JL_DOUBLE = "java/lang/Double";

        void DoubleNative::doubleToRawLongBits(std::shared_ptr<rtda::Frame> frame) {
            auto value = frame->getLocalVars().getDouble(0);
            uint64_t bits;
            std::memcpy(&bits, &value, sizeof(bits));
            frame->getOperandStack()->pushLong(static_cast<int64_t>(bits));
        }

        void DoubleNative::longBitsToDouble(std::shared_ptr<rtda::Frame> frame) {
            auto bits = frame->getLocalVars().getLong(0);
            double value;
            std::memcpy(&value, &bits, sizeof(value));
            //auto value = std::bit_cast<double>(static_cast<uint64_t>(bits));
            frame->getOperandStack()->pushDouble(value);
        }

    } // namespace lang
} // namespace jvm